package com.nfit.shopweb.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nfit.shopmodel.dto.product.CategoryBrandDto;
import com.nfit.shopmodel.entity.product.Brand;
import com.nfit.shopmodel.entity.product.CategoryBrand;
import com.nfit.shopweb.mapper.BrandMapper;
import com.nfit.shopweb.mapper.CategoryBrandMapper;

import com.nfit.shopweb.service.BrandService;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:BrandServiceImpl
 * Package:com.nfit.shopweb.service.impl
 * Description
 *
 * @Author L
 * @Create 2024/12/11 19:07
 */
@Schema(description = "品牌与分类品牌的业务处理")
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    @Autowired
    private CategoryBrandMapper categoryBrandMapper;

    /**
     * 查询所有品牌
     */
    @Override
    public PageInfo<List<Brand>> selectAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Brand> list = brandMapper.selectAll();
        return  new PageInfo(list);
    }

    /**
     * 查询所有的品牌数据
     */
    @Override
    public List<Brand> list() {
        return brandMapper.selectAll();
    }

    /**
     * 添加
     */
    @Override
    public void save(Brand brand) {
        brandMapper.save(brand);
    }

    @Override
    public void update(Brand brand) {
        brandMapper.update(brand);
    }

    @Override
    public void delete(Long id) {
        brandMapper.delete(id);
    }


    /**
     * 查询分类品牌数据
     * @param pageNum 当前页
     * @param pageSize 每页记录数
     * @param categoryBrandDto 条件查询
     */
    @Override
    public PageInfo<List<CategoryBrand>> selectCategoryBrand(Integer pageNum, Integer pageSize , CategoryBrandDto categoryBrandDto) {
        PageHelper.startPage(pageNum, pageSize);
        List<CategoryBrand> list = categoryBrandMapper.page(categoryBrandDto);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    /**
     *
     * 删除分类品牌
     * @param id 分类品牌id
     */
    @Override
    public void deleteCategoryBrand(Long id) {
        categoryBrandMapper.deleteCategoryBrand(id);
    }

    /**
     * 添加分类品牌
     */
    @Override
    public void saveCategoryBrand(CategoryBrand CategoryBrand) {
        categoryBrandMapper.saveCategoryBrand(CategoryBrand);
    }

    /**
     * 修改分类品牌
     */
    @Override
    public void updateCategoryBrand(CategoryBrand categoryBrand) {
        categoryBrandMapper.updateCategoryBrand(categoryBrand);
    }

    /**
     * 根据三级商品分类id查询对应商品分类下对应的品牌数据
     * @param category3Id 三级商品分类id
     */
    @Override
    public List<Brand> findByCategory3Id(Long category3Id) {
        return brandMapper.findByCategory3Id(category3Id);
    }


}
